package com.mrlee.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mrlee.bean.Cost;
import com.mrlee.mapper.CostMapper;
import com.mrlee.service.CostService;
import com.mrlee.utils.TimeUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by dllo on 18/3/13.
 */
@Service
public class CostServiceImpl implements CostService {

    @Resource
    private CostMapper costMapper;

    @Override
    public List<Cost> selectAllCost() {
        return costMapper.selectAllCost();
    }

    @Override
    public List<Cost> selectAllOpenCost() {
        return costMapper.selectAllOpenCost();
    }

    @Override
    public List<Cost> selectAllAscBybc() {
        return costMapper.selectAllAscBybc();
    }

    @Override
    public List<Cost> selectAllDescBybcost() {
//        System.out.println(costMapper.selectAllDescBybc());
        return costMapper.selectAllDescBybc();
    }

    @Override
    public List<Cost> selectAllAscBybd() {
        return costMapper.selectAllAscBybd();
    }

    @Override
    public List<Cost> selectAllDescBybd() {
        return costMapper.selectAllDescBybd();
    }

    @Override
    public int deleteCostById(Integer id) {
        return costMapper.deleteCostById(id);
    }

    @Override
    public int updateStById(Integer id) {
        String st = TimeUtils.time();
        return costMapper.updateStById(st,id);
    }

    @Override
    public Cost selectById(Integer id) {
        return costMapper.selectById(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Cost record) {
        return costMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int insert(Cost record) {
        return costMapper.insert(record);
    }

    @Override
    public PageInfo<Cost> queryCostByPage(Integer pageNo, Integer pageSize) {
        pageNo = pageNo == null ? 1 : pageNo;
        pageSize = pageSize == null ? 10 : pageSize;

        //这句话一定写在查询之前
        PageHelper.startPage(pageNo,pageSize);
        List<Cost> costList = costMapper.selectAllCost();
        PageInfo<Cost> costPageInfo = new PageInfo<Cost>(costList);
        return costPageInfo;
    }
}
